function ajax(url, data, methods) {
  return new Promise((resolve, reject)=> {
    let timer = true;
      setTimeout(()=>{
        if (timer) {
          wx.showLoading({
            title: '加载中...',
            mask: true
          })
        }
      }, 800)
    wx.request({
      url: url,
      data: data,
      method: methods,
      success: function(res) {
        if(res.statusCode === 200) {
          resolve(res)
        }else {
          wx.showToast({
            title: res.data.error_msg,
            icon: 'none'
          })
          reject(res)
        }
      },
      fail: function(err) {
        wx.showToast({
          title: err,
          icon: 'none'
        })
        reject(err)
      },
      complete: function() {
        timer = false
        wx.hideLoading()
        wx.stopPullDownRefresh()
      }
    })
  })
}

export default ajax